package com.zhj.rabbitmq.com.controller;

import com.zhj.rabbitmq.com.service.RabbitmqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: rabbimmq-demo
 * @description:
 * @author: zhengjibin
 * @create: 2020-11-19 13:57
 * @Version 1.0
 **/
@RestController
@RequestMapping("/rabbitmq")
public class RabbitmqSendController {
    @Autowired
    private RabbitmqService rabbitmqService;

    /**
     * 发送direct类型交换机消息
     * @param message
     * @return
     */
    @GetMapping("/sendDirectMessage")
    public String sendDirectMessage(@RequestParam("message") String message){
        rabbitmqService.sendDirectMessage(message);
        return "direct消息发送成功"+message;
    }

    /**
     * 读取消息 direct类型交换机消息
     */
    @GetMapping("/getDirectMessage")
    public String getDirectMessage(){
        String ms = rabbitmqService.directReceiveMessage();
        return ms;
    }

    /**
     * fanout类型消息发送
     */
    @GetMapping("/sendFanoutMessage")
    public String sendFanoutMessage(@RequestParam("message") String message){
        rabbitmqService.sendFanoutMessage(message);
        return "fanout消息发送成功"+message;
    }


    /**
     * topic 类型消息发送
     */
    @GetMapping("/sendTopicMessage")
    public String sendTopicMessage(@RequestParam("message") String message,@RequestParam("routingkey") String routingkey){
        rabbitmqService.sendTopicMessage(message,routingkey);
        return "fanout消息发送成功"+message+"---routingkey:"+routingkey;
    }

}
